<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>目标分解清单SOP模板</title>
    <script src="https://cdn.tailwindcss.com"></script>
    
    <!-- JS 库将移到 body 底部 -->
    
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;700&family=Source+Han+Sans+CN:wght@300;400;700&display=swap" rel="stylesheet">
    
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#3B82F6', // 蓝色
                        danger: '#EF4444', // 红色
                        'light-blue-bg': '#EFF6FF',
                        'dark-blue-text': '#1E40AF',
                        'icon-blue': '#60A5FA',
                        'icon-green': '#34D399',
                        'icon-purple': '#A78BFA',
                        'icon-orange': '#F59E0B',
                    }
                }
            }
        }
    </script>
    <style>
        /* 复用SaaS风格 */
        body {
            font-family: 'Source Han Sans CN', sans-serif;
            font-weight: 300;
            background-color: #f3f4f6;
        }
        h1, h2, h3, blockquote {
            font-family: 'Noto Serif SC', serif;
        }

        .tool-container {
            width: 1000px; 
            max-width: 90vw;
            background: #ffffff;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.08);
            margin: 40px auto;
            padding: 40px;
        }
        
        /* 导出按钮样式 */
        .export-btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            color: white;
            border: none;
            padding: 12px 28px;
            font-size: 1.0em;
            font-weight: 700;
            border-radius: 8px;
            cursor: pointer;
            transition: opacity 0.3s, transform 0.2s;
            font-family: 'Source Han Sans CN', sans-serif;
            text-decoration: none;
        }
        .btn-pdf {
            background-color: #EF4444; /* 红色 */
        }
        .btn-pdf:hover { opacity: 0.85; transform: translateY(-1px); }
        
        .btn-doc {
            background-color: #3B82F6; /* 蓝色 */
            margin-left: 16px;
        }
        .btn-doc:hover { opacity: 0.85; transform: translateY(-1px); }

        .export-btn.loading {
            background-color: #9ca3af;
            cursor: wait;
        }

        /* 笔记法标题图标 */
        .section-title-icon {
            width: 32px;
            height: 32px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: #EFF6FF;
            color: #3B82F6;
            flex-shrink: 0;
            margin-right: 12px;
        }

        /* 笔记法特定样式 */
        .column-header {
            display: flex;
            align-items: center;
            font-size: 1.2em;
            font-weight: 700;
            font-family: 'Noto Serif SC', serif;
            margin-bottom: 16px;
            margin-top: 24px; /* 模块间距 */
        }
        
        /* 编辑框 */
        .editable-box {
            width: 100%;
            min-height: 150px; 
            padding: 12px;
            border: 1px solid #e0e0e0;
            border-radius: 6px;
            background-color: #f9f9f9;
            font-size: 14px;
            line-height: 1.7;
            cursor: text;
        }
        .editable-box:focus {
            outline: 2px solid var(--theme-primary);
            background-color: #fff;
            border-color: var(--theme-primary);
        }
        .editable-box:empty:before {
            content: attr(data-placeholder);
            color: #aaa;
            font-style: italic;
            white-space: pre-line;
        }
        
        .box-helper-text {
            font-size: 0.875rem; 
            color: #6b7280; 
            margin-top: 8px;
            padding-left: 4px;
        }
        
        /* 打印时隐藏的元素 */
        @media print {
            .no-print { display: none; }
        }
        
    </style>
</head>
<body class="bg-gray-100">

    <div class="tool-container" id="goal-export-area">

        <!-- 页面头部 -->
        <header class="mb-8 no-print"> 
            <h1 class="text-3xl font-bold text-gray-800">目标分解清单SOP模板</h1>
            <p class="text-lg text-gray-500 mt-2">习惯管理与目标拆解工具</p>
        </header>

        <!-- 方法简介 -->
        <div class="bg-light-blue-bg border-l-4 border-primary p-6 rounded-lg my-6 no-print">
            <h3 class="font-bold text-lg text-dark-blue-text">方法简介</h3>
            <p class="text-gray-700 mt-2">
                “目标分解清单” 是将宏大愿景落地为具体行动的第一步。它帮助您将一个模糊的“目标”拆解为可量化的“子目标”，并最终落实为“行动清单”。
            </p>
        </div>

        <!-- 导出按钮区域 (移到末尾) -->

        <!-- 在线填写区域 -->
        <section id="goal-content" class="border-t border-gray-200 pt-8">
            
            <!-- 大标题 -->
            <div class="flex items-center mb-6">
                <div class="section-title-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><circle cx="12" cy="12" r="6"></circle><circle cx="12" cy="12" r="2"></circle></svg>
                </div>
                <h2 id="note-title" class="text-2xl font-bold text-gray-800" contenteditable="true">[请填写您的标题]</h2>
            </div>
            
            <!-- 垂直布局 -->
            <div style="display: block;">
                
                <!-- 1. 设置目标 -->
                <div>
                    <div class="column-header">
                        <span class="mr-2" style="color: #3B82F6;">
                            <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><circle cx="12" cy="12" r="6"></circle><circle cx="12" cy="12" r="2"></circle></svg>
                        </span>
                        Setting Goals (设置目标)
                    </div>
                    <div id="col-goal" class="editable-box" contenteditable="true" 
                         data-placeholder="您希望达成的、有挑战性的、鼓舞人心的总目标。
&#10;
例如：在6个月内，将我的个人品牌影响力提升一倍。">
                    </div>
                    <p class="box-helper-text">您的“北极星”，确保它足够清晰、有吸引力。</p>
                </div>

                <!-- 2. 分解目标 -->
                <div>
                    <div class="column-header">
                        <span class="mr-2" style="color: #F59E0B;">
                            <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"></path><circle cx="12" cy="10" r="3"></circle></svg>
                        </span>
                        Decomposition Goals (分解目标)
                    </div>
                    <div id="col-decomp" class="editable-box" contenteditable="true"
                         data-placeholder="为了实现总目标，需要达成的2-3个关键子目标 (KR)。
&#10;
例如：
1. 知识库工具售出500份。
2. 社交媒体粉丝数达到5万。
3. 完成一次成功的付费直播。">
                    </div>
                    <p class="box-helper-text">将大目标拆解为可衡量的关键结果。</p>
                </div>

                <!-- 3. 行动清单 -->
                <div>
                    <div class="column-header">
                        <span class="mr-2" style="color: #10B981;">
                            <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>
                        </span>
                        Action List (行动清单)
                    </div>
                    <div id="col-action" class="editable-box" contenteditable="true"
                         data-placeholder="为了实现上述子目标，您本周/本日需要执行的具体任务。
&#10;
例如：
- (对应子目标1) 制作3个SOP工具网页。
- (对应子目标2) 撰写2篇深度干货笔记。
- (对应子目标3) 规划直播主题和大纲。">
                    </div>
                    <p class="box-helper-text">这是您每天都可以对照执行的To-do List。</p>
                </div>
            </div>
        </section>
        
        <!-- 使用提示 -->
        <div class="bg-yellow-50 border border-yellow-200 p-6 rounded-lg my-8 no-print">
            <h3 class="font-bold text-lg text-yellow-800 flex items-center">
                <span class="mr-2 text-yellow-600">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <path d="M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1.3.5 2.6 1.5 3.5.7.8 1.3 1.5 1.5 2.5"></path>
                        <path d="M9 18h6"></path>
                        <path d="M10 22h4"></path>
                    </svg>
                </span>
                使用提示
            </h3>
            <ul class="list-disc pl-10 mt-4 text-gray-700 space-y-2">
                <li><b>设置目标 (Setting Goals)：</b> 确保您的目标是SMART的（具体的、可衡量的、可实现的、相关的、有时限的）。</li>
                <li><b>分解目标 (Decomposition Goals)：</b> 这是连接“梦想”与“现实”的桥梁，确保子目标能强力支撑总目标。</li>
                <li><b>行动清单 (Action List)：</b> 这是您唯一需要每天关注的。完成所有行动，子目标自然达成。</li>
            </ul>
        </div>
        
        <!-- 导出按钮区域 (移到末尾) -->
        <div class="text-center mt-12 no-print">
            <button class="export-btn btn-pdf" id="pdf-button">
                <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="mr-2"><path d="M14 2v6h6"></path><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><path d="M10 13v-1h4v1"></path><path d="M10 18h4"></path><path d="M10 15h4"></path></svg>
                导出为PDF
            </button>
            <a href="#" class="export-btn btn-doc" id="doc-button">
                <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="mr-2"><path d="M14 2v6h6"></path><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><path d="M10 13v-1h4v1"></path><path d="M10 18h4"></path><path d="M10 15h4"></path></svg>
                导出为文档
            </a>
        </div>
        
        <!-- 页脚 -->
        <div class="flex items-center text-green-600 mt-8 pt-6 border-t border-gray-200 dark:border-gray-700 no-print">
            <span class="mr-2">
                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>
            </span>
            <span>目标分解清单 · 职场观察者知识库工具</span>
        </div>
        <div class="h-16 no-print"></div> <!-- 底部留白 -->
        
    </div> <!-- .tool-container end -->

    <!-- JS 库 -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
    <!-- 移除了 lucide.js -->

    <script>
        window.onload = function() {
            // master try-catch
            try {
                // --- 1. 图标加载 (已通过内联SVG完成) ---

                // --- 2. PDF 生成功能 ---
                const pdfButton = document.getElementById('pdf-button');
                if (pdfButton) {
                    pdfButton.addEventListener('click', async function() {
                        if (typeof html2canvas === 'undefined' || typeof window.jspdf === 'undefined') {
                            alert("PDF生成库加载失败，请检查网络连接并刷新页面。");
                            return;
                        }
                        const { jsPDF } = window.jspdf;
                        const button = this;
                        const exportArea = document.getElementById('goal-export-area'); 
                        const title = document.getElementById('note-title').textContent.trim() || '目标分解清单';

                        button.classList.add('loading');
                        button.innerHTML = '<span><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block w-5 h-5 mr-2 animate-spin"><path d="M21 12a9 9 0 1 1-6.219-8.56"></path></svg> 正在生成PDF...</span>';
                        
                        window.scrollTo(0, 0);

                        try {
                            const canvas = await html2canvas(exportArea, {
                                scale: 2,
                                useCORS: true,
                                onclone: (doc) => {
                                    doc.querySelectorAll('.no-print').forEach(el => el.style.display = 'none');
                                    doc.querySelectorAll('.editable-box:empty:before').forEach(el => el.style.display = 'none');
                                }
                            });
                            
                            const imgData = canvas.toDataURL('image/png');
                            const pdfWidth = 595.28; // A4 纵向
                            const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
                            
                            const pdf = new jsPDF({
                                orientation: 'portrait',
                                unit: 'pt',
                                format: [pdfWidth, pdfHeight]
                            });
                            pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
                            pdf.save(`${title}.pdf`);

                        } catch (err) {
                            console.error('生成PDF失败: ', err);
                            alert("生成PDF失败，请重试。");
                        } finally {
                            button.classList.remove('loading');
                            button.innerHTML = '<span><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="mr-2 inline-block"><path d="M14 2v6h6"></path><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><path d="M10 13v-1h4v1"></path><path d="M10 18h4"></path><path d="M10 15h4"></path></svg> 导出为PDF</span>';
                        }
                    });
                }

                // --- 3. 导出Word文档功能 ---
                const docButton = document.getElementById('doc-button');
                if (docButton) {
                    let isDocFileReady = false;
                    docButton.addEventListener('click', function(e) {
                        if (isDocFileReady) {
                            isDocFileReady = false;
                            setTimeout(() => {
                                this.classList.remove('loading');
                                this.innerHTML = '<span><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="mr-2 inline-block"><path d="M14 2v6h6"></path><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><path d="M10 13v-1h4v1"></path><path d="M10 18h4"></path><path d="M10 15h4"></path></svg> 导出为文档</span>';
                            }, 1000);
                            return; 
                        }

                        e.preventDefault(); 
                        this.classList.add('loading');
                        this.innerHTML = '<span><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block w-5 h-5 mr-2 animate-spin"><path d="M21 12a9 9 0 1 1-6.219-8.56"></path></svg> 正在生成文档...</span>';

                        setTimeout(() => {
                            try {
                                const title = document.getElementById('note-title').innerHTML;
                                const goal = document.getElementById('col-goal').innerHTML;
                                const decomp = document.getElementById('col-decomp').innerHTML;
                                const action = document.getElementById('col-action').innerHTML;

                                // Word 样式
                                const h1Style = "font-family: 'Noto Serif SC', serif; color: #333; text-align: left; font-size: 1.8em; font-weight: 700; margin-bottom: 24px; border-bottom: 2px solid #f0f0f0; padding-bottom: 10px;";
                                const h2Style = "font-family: 'Noto Serif SC', serif; font-size: 1.25em; font-weight: 700; color: #3B82F6; margin-bottom: 12px;"; // 蓝色
                                const boxStyle = "padding: 12px; border: 1px solid #e0e0e0; border-radius: 6px; background-color: #f9f9f9; font-size: 14px; height: 150px; font-family: 'Source Han Sans CN', 'Microsoft YaHei', sans-serif; vertical-align: top;";
                                const helperStyle = "font-size: 12px; color: #6b7280; margin-top: 4px; font-family: 'Source Han Sans CN', 'Microsoft YaHei', sans-serif;";

                                // 辅助函数
                                function createModule(title, content, style, boxStyle, helperText) {
                                    return `
                                    <div style="margin-bottom: 20px;">
                                        <h2 style="${style}">${title}</h2>
                                        <table style="width: 100%; border-collapse: collapse;"><tr><td style="${boxStyle}">${content || '&nbsp;'}</td></tr></table>
                                        <p style="${helperStyle}">${helperText}</p>
                                    </div>
                                    `;
                                }

                                const wordHtmlContent = `
                                    <div style="font-family: 'Source Han Sans CN', 'Microsoft YaHei', sans-serif; margin: 30px; max-width: 900px;">
                                        <h1 style="${h1Style}">${title}</h1>
                                        ${createModule('Setting Goals (设置目标)', goal, h2Style, boxStyle, '您的“北极星”，确保它足够清晰、有吸引力。')}
                                        ${createModule('Decomposition Goals (分解目标)', decomp, h2Style.replace('#3B82F6', '#F59E0B'), boxStyle, '将大目标拆解为可衡量的关键结果。')}
                                        ${createModule('Action List (行动清单)', action, h2Style.replace('#3B82F6', '#10B981'), boxStyle, '这是您每天都可以对照执行的To-do List。')}
                                    </div>
                                `;
                                
                                const fullHtml = `<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><title>${title.replace(/<[^>]*>?/gm, '')}</title></head><body>${wordHtmlContent}</body></html>`;
                                const dataUri = 'data:application/vnd.ms-word;base64,' + btoa(unescape(encodeURIComponent(fullHtml)));
                                
                                this.href = dataUri;
                                this.download = `${title.replace(/<[^>]*>?/gm, '')}.doc`;
                                
                                this.classList.remove('loading');
                                this.innerHTML = '<span><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block w-5 h-5 mr-2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg> 已就绪, 请再次点击下载</span>';
                                
                                isDocFileReady = true;

                            } catch (err) {
                                console.error("生成Word失败:", err);
                                alert("生成文档失败，请重试。");
                                this.classList.remove('loading');
                                this.innerHTML = '<span><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="mr-2 inline-block"><path d="M14 2v6h6"></path><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><path d="M10 13v-1h4v1"></path><path d="M10 18h4"></path><path d="M10 15h4"></path></svg> 导出为文档</span>';
                            }
                        }, 100);
                    });
                }
                
            } catch (e) {
                console.error("A fatal error occurred during initialization:", e);
            }
        }
    </script>
</body>
</html>
